package demo.Day06;

import java.util.Arrays;
import java.util.Iterator;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/7/22-07-22-9:11
 * @Description：demo.Day06    数组
 */
public class array_use {
    public static void main(String[] args) {
        //new 关键字创建类的模板对象
        //其他情况1、System.out 方法内创建对象
        //其他情况2、 String s = ""; = new String("");
        //int数组类型唯一属性：length 数组的长度
        //数组 默认值和数组类型有关，
        //创建方式
            //1、先声明，然后创建，最后赋值
            //2、声明创建，并直接赋值，不需要写长度，   e.g. int[] arr = new int[]{1,2,3,4,5}   简写： int[] arr = {1,2,3,4,5}
        int[] arr = {23,21,3,54,2,5,7,16};
        Array_Sum_Max(arr);

        //二维数组  某一种创建方法
        int[][] arr_two = new int[4][];/*{{1,2,3},{4,5,6},{7,8,9}}*/;
        arr_two[0] = new int[2];
        arr_two[1] = new int[2];
        arr_two[2] = new int[2];
        arr_two[3] = new int[2];
        int[][] graph = {{1,1,1,0,0,1,0,0,0,0},
                         {1,1,0,1,1,0,0,0,0,0},
                         {1,0,1,0,0,0,0,0,0,0},
                         {0,1,0,1,0,0,0,0,0,0},
                         {0,1,0,0,1,0,0,0,0,0},
                         {1,0,0,0,0,1,0,0,0,0},
                         {0,0,0,0,0,0,1,1,1,0},
                         {0,0,0,0,0,0,1,1,0,0},
                         {0,0,0,0,0,0,1,0,0,1},
                         {0,0,0,0,0,0,0,0,1,1},
        };
        isReach(graph,9,7);
        System.out.println(isVisited[7]);
    }
    static boolean isVisited[] = new boolean[10];
    public static void isReach(int[][]graph, int start,int end){
        isVisited[start] = true;
        if(graph[start][end] != 0){
            isVisited[end] = true;
            return ;
        }else{
            for (int i = 0; i < 10; i++) {
                if(graph[start][i] != 0 && !isVisited[i]){
                    isReach(graph,i,end);
                }
            }
        }
    }

    public static void Array_Sum_Max(int[] arr) {
        int sum = arr[0],max=0;
        for (int i = 1; i < arr.length; i++) {
            sum = sum + arr[i];
            if(arr[max] < arr[i]){
                max = i;
            }
        }
        System.out.println(Arrays.toString(arr) + " 数组的平均数为： " + sum*1.0/arr.length + " 最大值为：" + arr[max]);
    }
}
